import setting
import baiduData
import coordinate as cdt
import pyecharts
from pyecharts.charts import Bar
from pyecharts import options as opts
from pyecharts.charts import Geo
from pyecharts.globals import ChartType, SymbolType
from pyecharts.charts import Map
from pyecharts.charts import BMap

def bar_demo(filename=""):
    bar = Bar()
    bar.add_xaxis(["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"])
    bar.add_yaxis("商家A", [5, 20, 36, 10, 75, 100])
    # render 会生成本地 HTML 文件，默认会在当前目录生成 render.html 文件
    # 也可以传入路径参数，如 bar.render("mycharts.html")
    if filename:
        bar.render(filename)
    else:
        bar.render()

def geo_base()->Geo:
    c = (
        Geo()
        .add_schema(maptype="china")
        .add("geo", [['大连', 56],
                     ['佳木斯', 118],
                     ['双鸭山', 57],
                     ['江西', 121],
                     ['湖南', 139],
                     ['浙江', 91],
                     ['江苏', 104]])
        .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
        .set_global_opts(
            visualmap_opts=opts.VisualMapOpts(),
            title_opts=opts.TitleOpts(title="Geo-基本示例"),
        )
    )
    return c

def map_base()->Map:
    value = [95.1, 23.2, 43.3, 66.4, 88.5,100]
    attr= ["China", "Canada", "Brazil", "Russia", "United States","Puerto Rico"]
    c = (
        Map()
        .add("世界地图", [list(z) for z in zip(attr, value)], maptype="world")
    )
    return c


def bmap_add_coordinate(theBMap,thelist,thetext):
    for i in thelist:
        (theBMap
            .add_coordinate(i[0],i[1],i[2])
            .add(thetext[0],[(i[0],i[3])],
                symbol_size=thetext[1],
                symbol=thetext[2],
                itemstyle_opts=opts.ItemStyleOpts(color=thetext[3])))
            # itemStyle_opts=opts.ItemStyleOpts(),

def bmap_base() -> BMap:
    
    thebmap = (
        BMap()
        .add_schema(
            baidu_ak=baiduData.BAIDU_AK_WEB,
            center=cdt.mapCenter,
            zoom=cdt.mapZoom,
        )
        .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
        .set_global_opts(title_opts=opts.TitleOpts(title="波多黎各地点分布图"))
    )
    theA = [
        ["1",-65.74,18.30,401],
        ["2",-66.13,18.41,402],
        ["3",-66.73,18.47,403],
    ]
    bmap_add_coordinate(thebmap,cdt.theH,["Hospital",16,"rect","#CC5B58"])
    bmap_add_coordinate(thebmap,cdt.theP,["Port",12,"triangle","#1488F6"])
    bmap_add_coordinate(thebmap,cdt.theC,["City",6,"circle","#000000"])
    # bmap_add_coordinate(thebmap,theA,["aaa",18,"circle","#111111"])
    return thebmap